package utils;

import com.jme.math.Vector3f;
import com.jme.renderer.Renderer;
import com.jme.scene.Spatial;
import com.jme.scene.Text;
import com.jme.system.DisplaySystem;
import com.jmex.game.state.BasicGameState;

public class ScoreGUIHandler extends BasicGameState {
	private int playerScore;
	private Text playerScoreText;
	private int player2Score;
	private Text player2ScoreText;
	public enum GameScoreType {
		/**
		 * This is for having a one player game. It will setup a score on the
		 * left for the AI and a score on the Right for the player
		 */
		OnePlayerGame;
	}

	public ScoreGUIHandler(Enum<GameScoreType> ScoreType) {
		super("Space Game");
		if (ScoreType == GameScoreType.OnePlayerGame) {
			initOnePlayerScoreGUI();
		}

	}

	private void initOnePlayerScoreGUI() {
		playerScoreText = Text.createDefaultTextLabel("playerScoreText",
				"Player Score");
		playerScoreText.setRenderQueueMode(Renderer.QUEUE_ORTHO);
		playerScoreText.setLightCombineMode(Spatial.LightCombineMode.Off);
		playerScoreText.setLocalTranslation(new Vector3f(0, DisplaySystem
				.getDisplaySystem().getHeight() / 2, 1));

		rootNode.attachChild(playerScoreText);

		player2ScoreText = Text.createDefaultTextLabel("Text","AI Score");
		player2ScoreText.setRenderQueueMode(Renderer.QUEUE_ORTHO);
		player2ScoreText.setLightCombineMode(Spatial.LightCombineMode.Off);
		player2ScoreText.setLocalTranslation(new Vector3f(DisplaySystem
				.getDisplaySystem().getWidth() -110, DisplaySystem
				.getDisplaySystem().getHeight() / 2, 1));
		rootNode.attachChild(player2ScoreText);

		rootNode.updateModelBound();
		rootNode.updateRenderState();
		rootNode.updateGeometricState(0, true);

		rootNode.updateModelBound();
	}

	private void updateScores() {
		 playerScoreText.getText().replace(0,playerScoreText.getText().length(), "Player Score \n" + playerScore);
		 player2ScoreText.getText().replace(0,player2ScoreText.getText().length(), "AI Score \n" + player2Score);
	}

	public void setPlayerScore(int playerScore) {
		this.playerScore = playerScore;
	}

	public void setPlayer2Score(int player2Score) {
		this.player2Score = player2Score;
	}

	public void update(float tpf) {
		updateScores();
		rootNode.updateGeometricState(tpf, true);
	}

}
